package fr.babostesting.tests
{
	import flash.events.MediaEvent;
	import flash.events.MouseEvent;
	import flash.media.CameraRoll;
	import flash.media.CameraUI;
	import flash.media.MediaType;
	import flash.text.TextFormatAlign;
	import fr.babos.core.entries.Document;
	import fr.babos.graphic.components.base.ResizableComponent;
	import fr.babos.graphic.components.base.StageWrapper;
	import fr.babos.graphic.components.bitmaps.AdvancedBitmap;
	import fr.babos.graphic.components.controls.text.Label;
	import fr.babos.graphic.components.controls.text.TextSkin;
	import fr.babos.graphic.components.medias.NativeVideoContainer;
	
	/**
	 * @author ZoulouX
	 */
	public class AirCameraTest extends Document
	{
		protected var _wrapper				:StageWrapper;
		protected var _videoPlayer			:NativeVideoContainer;
		
		public function AirCameraTest ()
		{
			
		}
		
		override public function init ():void
		{
			//var cameraRoll:CameraRoll = new CameraRoll();
			
			_wrapper = new StageWrapper(stage);
			
			
			var btn:ResizableComponent = new AdvancedBitmap(null, null, 1, 0xCCCCCC).radius(6);
			
			btn.size(200, 40).center(0, NaN).place(27, NaN, NaN, NaN).into(_wrapper);
			
			(new Label(false, false)).textSkin(new TextSkin( {
				font: "Arial",
				size: 15,
				align: TextFormatAlign.CENTER
			})).text("Enregistrer").place(9, 0, 0, 0).into(btn);
			
			btn.addEventListener(MouseEvent.CLICK, recordClickHandler);
			
			_videoPlayer = new NativeVideoContainer();
			_videoPlayer.place(100, 10, 10, 10).into(_wrapper);
		}
		
		protected function recordClickHandler (event:MouseEvent):void
		{
			if (CameraUI.isSupported)
			{
				var cameraUI:CameraUI = new CameraUI();
				cameraUI.addEventListener(MediaEvent.COMPLETE, mediaCompleteHandler);
				cameraUI.launch(MediaType.VIDEO);
			}
		}
		
		protected function mediaCompleteHandler (event:MediaEvent):void 
		{
			_videoPlayer.stageWebView.loadURL("file://" + event.data.file.nativePath);
			//_videoPlayer.loadVideo("file://" + event.data.file.nativePath);
		}
	}
}